﻿using System;
using System.ComponentModel;
using System.Linq;
using DoradoFramework.Core;

namespace Eflong.Tasks
{
    [Description( "辅助任务，用来为其他服务提供服务（仅测试时使用，生产环境设置为非启用状态）" )]
    internal class AssistTask : TaskTemplate<AssistTask>
    {
        public override bool Enabled
        {
            get
            {
#if DEBUG
                return true;
#else
                return false;
#endif
            }
            set
            {
                _enabled = value;
            }
        }

        /// <summary>
        /// 辅助任务
        /// </summary>
        protected override bool CreateTask( )
        {
            if ( TaskHandle == null )
            {
                TaskHandle = GlobalTimer<ITask>.Default.Add( TimeSpan.FromMilliseconds( 10000 ) , new TaskFuncAdapter( ( ) =>
                {
                    try
                    {
                    }
                    catch ( Exception ex )
                    {
                    }
                } ) , false );//不允许任务重入
            }
            else
            {
                TaskHandle.Start( );
            }
            return true;
        }

        /// <summary>
        /// 销毁联网数据接收服务心跳探测任务
        /// </summary>
        /// <returns></returns>
        protected override bool DisposeTask( )
        {
            if ( TaskHandle != null )
            {
                TaskHandle.Dispose( );
                TaskHandle = null;
                return true;
            }
            return false;
        }
    }
}